package com.osstem.hanarolab.relay.web;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.AbstractView;

import com.osstem.hanarolab.relay.service.RelayService;


/**
 * 릴레이 컨트롤러
 * 
 * @author 오스템임플란트 jw
 * @since 2012. 10. 4.
 * @version 1.0
 * @see
 * 
 * <pre>
 * << 개정이력(Modification Information) >>
 *   
 *	  수정일  		수정자				수정내용		
 *	----------		------		------------------------
 *	2012. 10. 4.    jw				최초 생성
 *
 * </pre>
 */
@Controller(value="RelayController")
@RequestMapping(value="/relay/relay.do")
public class RelayController {

	@Resource(name="RelayService")
	RelayService relayService;
	
	//전문처리
	@RequestMapping(params="method=relayMain")
	public ModelAndView relayMain(HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		ModelAndView mav = new ModelAndView();
				
		View view = new AbstractView(){
			@Override
			protected void renderMergedOutputModel(Map<String, Object> model,HttpServletRequest request, HttpServletResponse response) 	throws Exception {
		
				response.setContentType("text/html;charset=utf-8");
				
				//요청전문을 받는다.
				String plainText = (String)request.getParameter("plainText");
				String resultPlainText = relayService.managePlainText(plainText);
				
				StringBuffer sb = new StringBuffer();
				//sb.append(request.getParameter("plainText"));
				sb.append(resultPlainText);
		
				response.getWriter().write(sb.toString());
			}
		};
		
		mav.setView(view);
		
		return mav; 
	}
}